//
//  BRStaionListHeader.m
//  Kexu
//
//  Created by IOS on 2023/7/12.
//

#import "BRStaionListHeader.h"

@interface BRStaionListHeader ()<JXCategoryViewDelegate>

@end

@implementation BRStaionListHeader

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setUI];
    }
    return self;
}

#pragma mark - JXCategoryViewDelegate --
// 点击选中或者滚动选中都会调用该方法。适用于只关心选中事件，不关心具体是点击还是滚动选中的。
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
    
    NSLog(@"---[%ld]",index);
    if (self.itemSelBlock) self.itemSelBlock(index);
}


#pragma mark - UI --
- (void)setUI {
    self.backgroundColor = UIColor.clearColor;
    self.layer.masksToBounds = YES;
    UIView *contentView = [[UIView alloc] init];
    contentView.backgroundColor = kColorBGEC;
    contentView.layer.cornerRadius = 20;
    contentView.layer.masksToBounds = YES;
    [self addSubview:contentView];
    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(14);
        make.right.offset(-14);
        make.bottom.offset(-4);
        make.top.offset(-20);
    }];
    
    [contentView addSubview:self.jxTitleView];
    [self.jxTitleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.right.left.offset(0);
        make.height.mas_equalTo(44);
    }];
}

- (JXCategoryTitleView *)jxTitleView {
    
    if (_jxTitleView == nil) {
        _jxTitleView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth - 28, 36)];
        _jxTitleView.delegate = self;
//        _jxTitleView.backgroundColor = UIColor.qd_backgroundColorLighten2;
        _jxTitleView.titleSelectedColor = kColorTitle;
        _jxTitleView.titleSelectedFont = [UIFont br_fontB:14];
        _jxTitleView.titleColor = kColorTitle66B;
        _jxTitleView.layer.cornerRadius = 9;
        _jxTitleView.titleFont = [UIFont fontM:14];
        _jxTitleView.cellSpacing = 0;
        _jxTitleView.cellWidth = (kScreenWidth - 28) / 3.;
        
        JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
        lineView.indicatorColor = UIColorMakeWithRGBA(57, 64, 77, 0.4);
        lineView.indicatorWidth = 44;
        lineView.indicatorHeight = 2;
        lineView.indicatorCornerRadius = 1;
        _jxTitleView.indicators = @[lineView];
        _jxTitleView.titles = @[Localized(@"home_rent_tag"),Localized(@"home_return_tag"),Localized(@"home_all")];
    }
    
    return _jxTitleView;
}

@end


@implementation BRStaionListSubHeader

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setUI];
    }
    return self;
}

- (void)setItemIndex:(NSInteger)itemIndex {
    _itemIndex = itemIndex;
    CGFloat w = (kScreenWidth - 28) / 3.0 * itemIndex;
    
    [self.line mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.offset(self.linex + w);
    }];
}

#pragma mark - UI --
- (void)setUI {
    
    self.backgroundColor = UIColorClear;
    self.layer.masksToBounds = YES;
    UIView *contentView = [[UIView alloc] init];
    contentView.backgroundColor = kColorBGEC;
    contentView.layer.cornerRadius = 20;
    contentView.layer.masksToBounds = YES;
    [self addSubview:contentView];
    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(14);
        make.right.offset(-14);
        make.bottom.offset(0);
        make.top.offset(-20);
    }];
    
    CGFloat w = (kScreenWidth - 28) / 3.0;
    CGFloat wLine = w / 2.0 - 14;
    self.linex = wLine;
    [contentView addSubview:self.line];
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(28);
        make.height.mas_equalTo(2);
        make.bottom.offset(0.5);
        make.left.offset(wLine);
    }];
}

- (UIView *)line {
    
    if (_line == nil) {
        _line = [[UIView alloc] init];
        _line.backgroundColor = UIColorMakeWithHex(@"#39404D");
        _line.layer.cornerRadius = 1;
        _line.layer.masksToBounds = YES;
        _line.alpha = 0.4;
    }
    
    return _line;
}

@end
